﻿using MediatR;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.WhitestripWeighing
{
    public class WhiteStripWeighingSelectViewHandler : IRequestHandler<WhiteStripWeighingSelectViewCommond, Resqults>
    {


        /// <summary>
        /// 批宰计划
        /// </summary>
        private readonly IBateRepository<BulkSlaughter> _BulkSlaughter;
        /// <summary>
        /// 活畜称重
        /// </summary>
        private readonly IBateRepository<LiveAnimalweighing> _LiveAnimalweighing;

        public WhiteStripWeighingSelectViewHandler(IBateRepository<BulkSlaughter> bulkSlaughter, IBateRepository<LiveAnimalweighing> liveAnimalweighing)
        {
            _BulkSlaughter = bulkSlaughter;
            _LiveAnimalweighing = liveAnimalweighing;
        }

        public async Task<Resqults> Handle(WhiteStripWeighingSelectViewCommond request, CancellationToken cancellationToken)
        {

            var result = new Resqults { Code = 0 };

            var list = from a in _BulkSlaughter.GetAll()
                       join b in _LiveAnimalweighing.GetAll() on a.LiveAnimalweighingId equals b.LiveAnimalweighingId
                       select new
                       {
                           a.SlaughterTime,
                           b.NetWeight,
                           b.WeightNum,
                           a.BulkSlaughterNum,
                           b.LiveAnimalweighingNo,
                       };


            result.Date = list;

            return result ;



        }
    }
}
